package org.aplikator.client.descriptor;

import org.aplikator.client.panels.ContentsPanel;
import org.aplikator.client.widgets.FormWidget;
import org.aplikator.client.widgets.TableFactory;
import org.aplikator.client.widgets.TableInterface;

import com.google.gwt.user.client.ui.Widget;

@SuppressWarnings("serial")
public class TableDTO implements WidgetDTO {

    private PropertyDTO<Integer> property;
    private ViewDTO view;

    @SuppressWarnings("unused")
    private TableDTO() {
    }

    public TableDTO(PropertyDTO<Integer> property, ViewDTO view) {
        this.property = property;
        this.view = view;
    }

    public Widget getWidget(FormWidget form) {
        ContentsPanel frame = new ContentsPanel();
        TableInterface table = TableFactory.create(view, property, form);
        form.registerNestedCollection(table);
        frame.setContents(table.asWidget());
        frame.setTitle(view.getLocalizedName());
        frame.setHeight("" + (6 + 2 * (view.getPageSize() > 0 ? view.getPageSize() : 15)) + "em");// TODO
                                                                                                                // nahradit
                                                                                                                // 15
                                                                                                                // za
                                                                                                                // DEFAULTPAGESIZE,
                                                                                                                // po
                                                                                                                // jejim
                                                                                                                // presunuti
                                                                                                                // do
                                                                                                                // konstant
        frame.setWidth("100%");// TODO doplnit podporu explicitni sirky
        return frame;
    }

}
